package util;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;

import domain.Question;

public class QuestionFileReader {
	//程序执行时 将文件中的所有题目 一次性读取出来
	private HashSet<Question> questionBox = new HashSet<>();
	{
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader("src//dbfile//Question.txt"));
			String message = reader.readLine();
			while(message!=null) {
				String[] values = message.split("#");
				if(values.length==2) {
					questionBox.add(new Question(values[0],values[1]));
				}else if(values.length==3) {
					questionBox.add(new Question(values[0],values[1],values[2]));
				}
				message = reader.readLine();
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			try {
				if(reader!=null) {
					reader.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	public HashSet<Question> getQuestionBox(){
		return questionBox;
	}
}
